home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 40 / Amiga Format CD40 (1999-05-11)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-06].iso / -seriously_amiga- / misc / blankpurge / blankpurge.bas < prev    next >
BASIC Source File  |  1999-03-29  |  3KB  |  154 lines

  1. REM Blank Purger 1.2 by Simon N Goodwin, February 1999.
  2. REM
  3. REM WHAT?
  4. REM
  5. REM Program to scan a text file and remove blank lines.
  6. REM
  7. REM REQUIREMENTS
  8. REM
  9. REM Written in HiSoft BASIC. Requires ASL library.
  10. REM Uses 15 point Helvetica.font if it's available.
  11. REM
  12. REM HOW?
  13. REM 
  14. REM Start from Workbench by clicking on the icon.
  15. REM Select a file to be scanned or CANCEL to quit.
  16. REM Repeat selection for each file to be purged.
  17. REM
  18. REM Input file is not modified. A new file on the
  19. REM same path with the suffix ".purged" is created
  20. REM containing the original contents except with
  21. REM the blank lines removed.
  22. REM
  23. REM KNOWN BUGS
  24. REM
  25. REM No check that the output file name is valid.
  26. REM
  27. REM FUTURE
  28. REM
  29. REM Progress display - tricky without a prior scan.
  30. REM
  31. REM Could be extended to skip lines with no semantic
  32. REM content - e.g. containing only spaces or tabs,
  33. REM or empty comment lines (white space optionally
  34. REM either side of a REM, * or ; null line comment)
  35. REM
  36. REM Might also strip redundant CHR$(13)s, though
  37. REM that's easily done with Frank Swift's CRLF tool.
  38. REM
  39. REM STATUS
  40. REM
  41. REM Freely distributable; you must include source.
  42. REM
  43. REM AUTHOR
  44. REM
  45. REM Simon N Goodwin, simon@studio.woden.com
  46. REM
  47.  
  48. DEFINT a-z
  49.  
  50. ' HiSoft ASL library and disk font initialisation
  51.  
  52. REM $INCLUDE diskfont.bh
  53. REM $INCLUDE graphics.bh
  54. REM $include asl.bh
  55. LIBRARY OPEN "asl.library"
  56. LIBRARY OPEN "diskfont.library"
  57. LIBRARY OPEN "graphics.library"
  58.  
  59. WINDOW 1,"  Amiga File Blank Line Purger v1.2  ", _
  60.     (64,60)-(408,100),1+2+4+16+256
  61.  
  62. REM Use a groovier Compugraphic fo(u)nt if you wish
  63.  
  64. DIM TextAttr(4)
  65. InitTextAttr TextAttr(),"Helvetica.font",15,0,0
  66. font& = OpenDiskFont (VARPTR(TextAttr(0)))
  67.  
  68. IF font&
  69.   SetFont WINDOW (8), font&
  70. ELSE
  71.   PRINT " **** Preferred font not available. Using default."
  72. END IF
  73.  
  74. ' ASL requester initialisation
  75.  
  76. CONST TAG_DONE&=0,TRUE&=1,ABORT&=-1,FALSE&=0
  77. DIM frtags&(20)
  78.  
  79. ' Main program
  80.  
  81. ok=TRUE
  82.  
  83. REPEAT main
  84.     
  85.     TAGLIST VARPTR(frtags&(0)),ASLFR_TitleText&, _
  86.         "Select the file to be purged", _
  87.         ASLFR_InitialFile&,"", _
  88.         ASLFR_InitialDrawer&,"RAM:", _
  89.         ASLFR_InitialHeight&,     130, _
  90.         ASLFR_InitialLeftEdge&, 280, _
  91.         ASLFR_InitialWidth&,         310, _ 
  92.         TAG_DONE&
  93.         
  94.     fr&=AllocAslRequest&(ASL_FileRequest&,VARPTR(frtags&(0)))
  95.     IF fr& THEN
  96.         ok&=AslRequest&(fr&,0)
  97.         IF ok& THEN
  98.             file$=PEEK$(PEEKL(fr&+fr_File))
  99.             dir$=PEEK$(PEEKL(fr&+fr_Drawer))
  100.             IF LEN(dir$)
  101.                 suffix$=RIGHT$(dir$,1)
  102.                 IF suffix$<>"/" AND suffix$<>":" THEN dir$=dir$+"/"
  103.             END IF
  104.         END IF
  105.         FreeASlRequest fr&
  106.     ELSE
  107.         ok&=ABORT&
  108.     END IF
  109.  
  110.   IF ok&=FALSE& OR ok&=ABORT& THEN EXIT main
  111.  
  112.   file$=dir$+file$
  113.   
  114.     PRINT
  115.  
  116.     OPEN file$ FOR INPUT AS #3
  117.     OPEN file$+".purged" FOR OUTPUT AS #4
  118.  
  119.   PRINT " Scanning ";file$
  120.     found&=0
  121.  
  122.     REPEAT scan
  123.       IF EOF(3) THEN EXIT scan
  124.       LINE INPUT #3,a$
  125.       IF LEN(a$)
  126.         PRINT #4,a$ :REM debug PRINT a$
  127.       ELSE
  128.         found&=found&+1
  129.       END IF
  130.     END REPEAT scan 
  131.  
  132.     CLOSE #4
  133.     CLOSE #3
  134.  
  135.     PRINT
  136.     PRINT " OK,";found&;"empty lines";
  137.     IF found&<>1 THEN PRINT "s";
  138.     PRINT " found."
  139.     PRINT
  140.     PRINT " Condensed version written to ";file$+".purged"
  141.     
  142. END REPEAT main
  143.  
  144. SYSTEM
  145.  
  146. SUB InitTextAttr(T(1),FontName$,BYVAL Height,BYVAL style,BYVAL flags)
  147.  
  148. POKEL VARPTR(T(0))+ta_Name,SADD(FontName$+CHR$(0))
  149. t(ta_YSize\2)=Height
  150. POKEB VARPTR(T(0))+ta_Style,style
  151. POKEB VARPTR(T(0))+ta_Flags,flags
  152.  
  153. END SUB ' InitTextAttr
  154.